package org.ycx.upms.dao.auto;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.ycx.upms.dao.model.SecRole;
import org.ycx.upms.dao.model.SecRoleExample;

import java.util.List;

public interface SecRoleMapper {
    @SelectProvider(type=SecRoleSqlProvider.class, method="countByExample")
    long countByExample(SecRoleExample example);

    @DeleteProvider(type=SecRoleSqlProvider.class, method="deleteByExample")
    int deleteByExample(SecRoleExample example);

    @Delete({
        "delete from sec_role",
        "where RID = #{rid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer rid);

    @Insert({
        "insert into sec_role (ROLE_NAME, ROLE_DESC, ",
        "USER_COUNT, ROLE_STATE, ",
        "CREATE_TS, CREATE_UID, ",
        "UPDATE_TS, UPDATE_UID)",
        "values (#{roleName,jdbcType=VARCHAR}, #{roleDesc,jdbcType=VARCHAR}, ",
        "#{userCount,jdbcType=INTEGER}, #{roleState,jdbcType=VARCHAR}, ",
        "#{createTs,jdbcType=DATE}, #{createUid,jdbcType=INTEGER}, ",
        "#{updateTs,jdbcType=DATE}, #{updateUid,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="rid", before=false, resultType=Integer.class)
    int insert(SecRole record);

    @InsertProvider(type=SecRoleSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="rid", before=false, resultType=Integer.class)
    int insertSelective(SecRole record);

    @SelectProvider(type=SecRoleSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="RID", property="rid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ROLE_NAME", property="roleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_DESC", property="roleDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_COUNT", property="userCount", jdbcType=JdbcType.INTEGER),
        @Result(column="ROLE_STATE", property="roleState", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TS", property="createTs", jdbcType=JdbcType.DATE),
        @Result(column="CREATE_UID", property="createUid", jdbcType=JdbcType.INTEGER),
        @Result(column="UPDATE_TS", property="updateTs", jdbcType=JdbcType.DATE),
        @Result(column="UPDATE_UID", property="updateUid", jdbcType=JdbcType.INTEGER)
    })
    List<SecRole> selectByExample(SecRoleExample example);

    @Select({
        "select",
        "RID, ROLE_NAME, ROLE_DESC, USER_COUNT, ROLE_STATE, CREATE_TS, CREATE_UID, UPDATE_TS, ",
        "UPDATE_UID",
        "from sec_role",
        "where RID = #{rid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="RID", property="rid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ROLE_NAME", property="roleName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ROLE_DESC", property="roleDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_COUNT", property="userCount", jdbcType=JdbcType.INTEGER),
        @Result(column="ROLE_STATE", property="roleState", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TS", property="createTs", jdbcType=JdbcType.DATE),
        @Result(column="CREATE_UID", property="createUid", jdbcType=JdbcType.INTEGER),
        @Result(column="UPDATE_TS", property="updateTs", jdbcType=JdbcType.DATE),
        @Result(column="UPDATE_UID", property="updateUid", jdbcType=JdbcType.INTEGER)
    })
    SecRole selectByPrimaryKey(Integer rid);

    @UpdateProvider(type=SecRoleSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SecRole record, @Param("example") SecRoleExample example);

    @UpdateProvider(type=SecRoleSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") SecRole record, @Param("example") SecRoleExample example);

    @UpdateProvider(type=SecRoleSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SecRole record);

    @Update({
        "update sec_role",
        "set ROLE_NAME = #{roleName,jdbcType=VARCHAR},",
          "ROLE_DESC = #{roleDesc,jdbcType=VARCHAR},",
          "USER_COUNT = #{userCount,jdbcType=INTEGER},",
          "ROLE_STATE = #{roleState,jdbcType=VARCHAR},",
          "CREATE_TS = #{createTs,jdbcType=DATE},",
          "CREATE_UID = #{createUid,jdbcType=INTEGER},",
          "UPDATE_TS = #{updateTs,jdbcType=DATE},",
          "UPDATE_UID = #{updateUid,jdbcType=INTEGER}",
        "where RID = #{rid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(SecRole record);
}